<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>简单任务记录</title>
    <style>
        /* 基础样式重置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            color: #333;
            line-height: 1.6;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            width: 100%;
            max-width: 500px;
            background-color: white;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            padding: 25px;
        }

        /* 标题区域 */
        header {
            text-align: center;
            margin-bottom: 25px;
        }

        header h1 {
            color: #2c3e50;
            margin-bottom: 8px;
            font-size: 28px;
        }

        header p {
            color: #7f8c8d;
            font-size: 16px;
        }

        /* 输入区域 */
        .input-section {
            display: flex;
            margin-bottom: 20px;
            gap: 10px;
        }

        #taskInput {
            flex: 1;
            padding: 12px 15px;
            border: 2px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        #taskInput:focus {
            outline: none;
            border-color: #3498db;
        }

        #addTaskBtn {
            padding: 12px 20px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: bold;
            transition: background-color 0.3s;
        }

        #addTaskBtn:hover {
            background-color: #2980b9;
        }

        /* 任务列表 */
        #taskList {
            list-style-type: none;
            margin-bottom: 20px;
        }

        .task-item {
            display: flex;
            align-items: center;
            padding: 12px 15px;
            background-color: #f9f9f9;
            border-radius: 6px;
            margin-bottom: 10px;
            animation: fadeIn 0.3s;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .task-text {
            flex: 1;
            margin: 0 15px;
            word-break: break-word;
        }

        .task-completed .task-text {
            text-decoration: line-through;
            color: #95a5a6;
        }

        .task-checkbox {
            width: 20px;
            height: 20px;
            cursor: pointer;
        }

        .delete-btn {
            background: none;
            border: none;
            color: #e74c3c;
            cursor: pointer;
            font-size: 18px;
            opacity: 0.7;
            transition: opacity 0.3s;
        }

        .delete-btn:hover {
            opacity: 1;
        }

        /* 底部统计 */
        .stats {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-top: 15px;
            border-top: 1px solid #eee;
            font-size: 14px;
            color: #7f8c8d;
        }

        #clearCompleted {
            padding: 6px 12px;
            background-color: transparent;
            color: #e74c3c;
            border: 1px solid #e74c3c;
            border-radius: 4px;
            cursor: pointer;
            transition: all 0.3s;
        }

        #clearCompleted:hover {
            background-color: #e74c3c;
            color: white;
        }

        /* 空状态 */
        .empty-state {
            text-align: center;
            padding: 30px 0;
            color: #95a5a6;
        }

        /* 响应式设计 */
        @media (max-width: 600px) {
            body {
                padding: 10px;
            }
            
            .container {
                padding: 20px 15px;
            }
            
            .input-section {
                flex-direction: column;
            }
            
            #addTaskBtn {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>任务清单</h1>
            <p>添加和管理您的日常任务</p>
        </header>
        
        <div class="input-section">
            <input type="text" id="taskInput" placeholder="输入新任务...">
            <button id="addTaskBtn">添加</button>
        </div>
        
        <ul id="taskList">
            <div class="empty-state">暂无任务，请添加新任务</div>
        </ul>
        
        <div class="stats">
            <span id="tasksCount">0 个任务</span>
            <button id="clearCompleted">清除已完成</button>
        </div>
    </div>
    
    <script>
        // 任务管理应用
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const taskInput = document.getElementById('taskInput');
            const addTaskBtn = document.getElementById('addTaskBtn');
            const taskList = document.getElementById('taskList');
            const tasksCount = document.getElementById('tasksCount');
            const clearCompletedBtn = document.getElementById('clearCompleted');
            
            // 从本地存储加载任务
            let tasks = JSON.parse(localStorage.getItem('tasks')) || [];
            
            // 初始化应用
            function init() {
                renderTasks();
                updateTasksCount();
                
                // 添加事件监听器
                addTaskBtn.addEventListener('click', addTask);
                taskInput.addEventListener('keypress', function(e) {
                    if (e.key === 'Enter') {
                        addTask();
                    }
                });
                
                clearCompletedBtn.addEventListener('click', clearCompletedTasks);
            }
            
            // 添加新任务
            function addTask() {
                const taskText = taskInput.value.trim();
                
                if (taskText === '') {
                    alert('请输入任务内容');
                    return;
                }
                
                // 创建新任务对象
                const newTask = {
                    id: Date.now(),
                    text: taskText,
                    completed: false,
                    createdAt: new Date().toISOString()
                };
                
                // 添加到任务数组
                tasks.push(newTask);
                
                // 保存到本地存储
                saveTasks();
                
                // 清空输入框
                taskInput.value = '';
                
                // 重新渲染任务列表
                renderTasks();
                updateTasksCount();
            }
            
            // 渲染任务列表
            function renderTasks() {
                // 清空当前列表
                taskList.innerHTML = '';
                
                if (tasks.length === 0) {
                    taskList.innerHTML = '<div class="empty-state">暂无任务，请添加新任务</div>';
                    return;
                }
                
                // 渲染每个任务
                tasks.forEach(task => {
                    const li = document.createElement('li');
                    li.className = `task-item ${task.completed ? 'task-completed' : ''}`;
                    li.dataset.id = task.id;
                    
                    li.innerHTML = `
                        <input type="checkbox" class="task-checkbox" ${task.completed ? 'checked' : ''}>
                        <span class="task-text">${task.text}</span>
                        <button class="delete-btn">×</button>
                    `;
                    
                    // 添加事件监听器
                    const checkbox = li.querySelector('.task-checkbox');
                    checkbox.addEventListener('change', () => toggleTaskCompleted(task.id));
                    
                    const deleteBtn = li.querySelector('.delete-btn');
                    deleteBtn.addEventListener('click', () => deleteTask(task.id));
                    
                    taskList.appendChild(li);
                });
            }
            
            // 切换任务完成状态
            function toggleTaskCompleted(id) {
                tasks = tasks.map(task => {
                    if (task.id === id) {
                        return { ...task, completed: !task.completed };
                    }
                    return task;
                });
                
                saveTasks();
                renderTasks();
                updateTasksCount();
            }
            
            // 删除任务
            function deleteTask(id) {
                tasks = tasks.filter(task => task.id !== id);
                saveTasks();
                renderTasks();
                updateTasksCount();
            }
            
            // 清除已完成任务
            function clearCompletedTasks() {
                tasks = tasks.filter(task => !task.completed);
                saveTasks();
                renderTasks();
                updateTasksCount();
            }
            
            // 更新任务计数
            function updateTasksCount() {
                const totalTasks = tasks.length;
                const completedTasks = tasks.filter(task => task.completed).length;
                const remainingTasks = totalTasks - completedTasks;
                
                tasksCount.textContent = `${remainingTasks} 个待完成，${completedTasks} 个已完成`;
            }
            
            // 保存任务到本地存储
            function saveTasks() {
                localStorage.setItem('tasks', JSON.stringify(tasks));
            }
            
            // 初始化应用
            init();
        });
    </script>
</body>
</html>